clear;
tic

addpath('..\Utilities')  


% Set sector specific parameters
%***************************************************************
% NB: Edges of the rad grid need to be extra padded in the multi-sector 
% model because the sectors have different mean rad.

NSectors = 1;
sm = 0.0;

%0.0552582422061334 0.0345297530098889 -3.22066898186641 0.850810309615751

p0=[0.01:0.005:0.085]';
mu_c=[0.01:0.0025:0.05]';
sig_eps=[0.015:0.0025:0.05]';
rho_a=[0.5:0.02:0.75]';


%p_a=[0.4:0.03:0.98]';
%0.0517    0.0409    0.0731    0.1013
s=size(p0,1)+size(mu_c,1)+size(sig_eps,1)+size(rho_a,1);
%param0=[0.049 ;   0.024   ; 0.0381 ;   0.653];
%0.1440    0.0498    0.0329    0.0336    0.6385
param0=[0.0507 ;   0.0329 ;   0.0323  ;  0.6322];
%param0=[0.0518 ;   0.0413;   0.0745  ; 0.1023];
%0.0518    0.0412    0.0745    0.1020%
param=repmat(param0,1,s)';

param(1:size(p0),1)=p0;
param(size(p0)+1:size(p0)+size(mu_c),2)=mu_c;
param(size(p0)+size(mu_c)+1:size(p0)+size(mu_c)+size(sig_eps),3)=sig_eps;
param(size(p0)+size(mu_c)+size(sig_eps)+1:size(p0)+size(mu_c)+size(sig_eps)+size(rho_a,1),4)=rho_a;



s=size(param)
mu_vec=0.00125;

size_mu=1;
for ii=1:size_mu;
    
mu_loop=mu_vec*ii;
     fprintf("ii");
     disp(ii);
%for jj=1+s*(ii-1):ii*s;
for jj=1:s;
     fprintf("jj");
     disp(jj);
     %"i" i);
    p0=param(jj,1);
    mu_c=param(jj,2);
    sig_eps_a=param(jj,3);
    %p_a=param(jj,4); 
    rho_a=param(jj,4);
    weight_j=0.57;    
 
   [f2, avfracup2,    med2,med21,med22,   interq2, kur2]=geNCalvoPlus_SMM(mu_loop, p0, mu_c, sig_eps_a, rho_a, weight_j);
 
  stat_temp(jj,:)=[ii param(jj,:) f2 avfracup2      med2    interq2 kur2 med21 med22];

%  save stat_outsample_1118egb stat_outsample_1118egb;
end

stat_outsample_testb(1+s*(ii-1):ii*s,:)=stat_temp

save stat_outsample_testb stat_outsample_testb;


end